DEFINITION MODULE DecimalOps;


  PROCEDURE PrepareDecimal (VAR Str1 : ARRAY OF CHAR;
                                Len,
                                DP   : CARDINAL);

    (* This procedure is normally used by the decimal conversion
       procedures, but is provided here as an extra tool.

       The procedure's main aim is to make sure that a decimal is in the
       correct format (i.e. that it has the correct number of decimal
       places and no unnecessary characters)

       It does the following functions (read as "number becomes new
       number") :

         i) Front Zero added if number < 1 :
              '.125'     -->   '0.125'

        ii) Front zero removed if next character is not a decimal point :
              '07.125'   -->   '7.125'

       [Note - For steps i) and ii) above, if the number is negative the
               resultant string will be the same format as above but with
               the `-' sign in front.  e.g.  -.125   -->   -0.125]

       iii) If too few decimal places then zeros added to make correct
            length :
              '1.25' (with 3 d.p.)   -->   '1.250'

        iv) If there are too many decimal places, the remove least
            significant figures :
              '1.125' (with 2 d.p.)  -->   '1.12'

         v) Make sure string is correct length (right justified) :
              '1.125' (with 3 d.p. & len 10)   -->   '     1.125'

        vi) If input string is null (i.e. Str [0] = 0C) :
              '' (with 3 d.p. & len 10)   -->   '     0.000' 

       vii) If input string is an integer, then insert decimal places :
              '3' (with 3 d.p. & length 10)   -->   '     3.000'  *)


  PROCEDURE DecToString (    Dec           : ARRAY OF CHAR;
                         VAR Str           : ARRAY OF CHAR;
                             Len,
                             DecimalPlaces : CARDINAL);

    (* This procedure will convert a decimal Dec to a string Str.  Any 
       spaces at the front of the string will be removed.
       [DTS = DecToString]

       e.g. DTS ('  1.125', Str, 7, 3)   -->   Str = '1125'
            DTS ('  1.125', Str, 7, 2)   -->   Str = '112'
            DTS ('  1.125', Str, 3, 3)   -->   Str = '1125'  *)


  PROCEDURE StringToDec (    Str           : ARRAY OF CHAR;
                         VAR Dec           : ARRAY OF CHAR;
                             Len,
                             DecimalPlaces : CARDINAL);

    (* This procedure will convert a string of numbers into a decimal string
       of numbers.  No attempt is made to check that Str is a valid number.
       [STD = StringToDec]

       e.g. STD ('1125', Dec, 5, 3)   -->   Dec = '1.125'
            STD ('1125', Dec, 10, 2)  -->   Dec = '     11.25'
            STD ('1125', Dec, 4, 3)   -->   Dec = '1.125'  *)

END DecimalOps.